local nya__qieting = fk.CreateSkill {

  name = "nya__qieting",

  tags = {  },

}



nya__qieting:addEffect(fk.EventPhaseChanging, {
  name = "nya__qieting",
  anim_type = "control",
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(nya__qieting.name) and target ~= player and data.to == Player.NotActive
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"draw1"}
    if target:canMoveCardsInBoardTo(player, "e") then
      table.insert(choices, 1, "nya__qieting_move")
    end
    local choice = room:askForChoice(player, choices, nya__qieting.name, "#nya__qieting-choice::"..target.id)
    if choice == "nya__qieting_move" then
      room:doIndicate(player.id, {target.id})
      room:askForMoveCardInBoard(player, target, player, nya__qieting.name, "e", target)
    else
      player:drawCards(1, nya__qieting.name)
    end
    if target:hasSkill("nya__play", true) and not player.dead then
      choices = {"Cancel", "draw1"}
      if not target:isKongcheng() then
        table.insert(choices, 2, "nya__qieting_prey")
      end
      choice = room:askForChoice(player, choices, nya__qieting.name, "#nya__qieting-choice::"..target.id)
      if choice == "nya__qieting_prey" then
        room:doIndicate(player.id, {target.id})
        local ids = table.random(target:getCardIds("h"), 2)
        local result = room:askForGuanxing(player, ids, {0, 2}, {1, 1}, nya__qieting.name, true, {target.general, "nya__qieting_get"})
        local id
        if #result.bottom > 0 then
          id = result.bottom[1]
        else
          id = table.random(target:getCardIds("h"))
        end
        room:obtainCard(player, id, false, fk.ReasonPrey)
      elseif choice == "draw1" then
        player:drawCards(1, nya__qieting.name)
      end
    end
  end,
})

return nya__qieting